package com.hs.srm.admin.modules.invoice.service.impl;

import java.util.List;
import java.util.Map;

import com.hs.srm.admin.modules.invoice.entity.ScmInvoiceHeaderEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import sunnykid.text.SunnykidText;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.hs.srm.admin.modules.invoice.dao.InvoiceDao;
import com.hs.srm.admin.modules.invoice.entity.ScmInvoiceEntity;
import com.hs.srm.admin.modules.invoice.service.InvoiceService;
import com.hs.srm.base.common.utils.QueryParam;
import com.hs.srm.common.utils.PageUtils;

/**
 * 发票数据Service控制层实现类
 * <p>標題：</p>
 * <p>描述：</p>
 * <p>版權：版權所有 (c) 2019</p>
 * <p>組織：厚声集团</p>
 *
 * @author 鐘曉籟
 * @version V1.0.0
 * @date 2019年4月2日 上午9:46:29
 * @since V1.0.0
 */
@Service("invoiceService")
public class InvoiceServiceImpl extends ServiceImpl<InvoiceDao, ScmInvoiceEntity> implements InvoiceService {

    @Autowired
    private InvoiceDao invoiceDao;

    @Override
    public PageUtils selectDetailPage(Map<String, Object> params) {
        Page<ScmInvoiceEntity> page = this.selectDetailPage(new QueryParam<ScmInvoiceEntity>(params).getPage(),
                new EntityWrapper<ScmInvoiceEntity>(), params);
        return new PageUtils(page);
    }

    private Page<ScmInvoiceEntity> selectDetailPage(Page<ScmInvoiceEntity> page, Wrapper<ScmInvoiceEntity> wrapper,
                                                    Map<String, Object> params) {
        page.setRecords(this.baseMapper.selectDetailPage(page, wrapper, params));
        return page;
    }

    @Override
    public int genInvoices(String[] billIds) {
//		List<ScmBillsEntity> list = this.invoiceDao.findByStockId(billIds);
//		String billNo = this.generateBillNo();
//		for(ScmBillsEntity bill : list) {
//			bill.setBillNo(billNo);
//			bill.setCreatePeople(ShiroUtils.getUserEntity().getUsername());
//			bill.setCreateTime(new Date());
//			this.scmBillsDao.insert(bill);
//		}
//		this.stockDao.updateStockStatus(stockIds);
//		return list.size();
        return 0;
    }

    /**
     * 生成对发票号
     *
     * @return String
     */
    private String generateInvoiceNo() {
        return SunnykidText.getUUID();
    }

    @Override
    public List<String> poNosForAdd() {
        return invoiceDao.poNosForAdd();
    }

    @Override
    public boolean insertInvoice(ScmInvoiceEntity entity) {
        boolean flg = this.insert(entity);
        return flg;
    }




}
